package donjuan;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
//提示用户输入账户名，密码，以及依据选择来展示创建的新数据表填写框
public class Window_ready extends JPanel implements ActionListener {
  static String[] contain = new String[3];//第一个为账户名，第二个密码，第三个读取表名
  
  JTextField[] cin = new JTextField[3];
  
  JLabel[] hint = new JLabel[3];
  
  JSplitPane[] frame = new JSplitPane[3];
  
  JSplitPane[] frame2 = new JSplitPane[3];
  
  JButton done = new JButton("完成");
  
  Window_ready() {
    setVisible(true);
    setBounds(50, 50, 300, 300);
    setName("请输入信息");
    setLayout(new FlowLayout());
    init();
  }
  void init() {
    this.hint[0] = new JLabel("用户名");
    this.hint[1] = new JLabel("密码");
    this.hint[2] = new JLabel("新建数据表名：");
    int i;
    for (i = 0; i < 3; i++) {
      this.cin[i] = new JTextField(20);
      this.cin[i].setPreferredSize(new Dimension(20, 40));
      this.frame[i] = new JSplitPane(1, this.hint[i], this.cin[i]);
    } 
    this.frame2[0] = new JSplitPane(0, this.frame[0], this.frame[1]);
    this.frame2[1] = new JSplitPane(0, this.frame2[0], this.frame[2]);
    this.frame2[2] = new JSplitPane(0, this.frame2[1], this.done);
    this.done.addActionListener(this);
    for (i = 0; i < 3; i++)
      this.cin[i].addActionListener(this); 
    add(this.frame2[2]);
    done.setBorder(BorderFactory.createRaisedBevelBorder());
    done.setFont(new Font("华文行楷",1,15));
  }
  
  void changemode(int i) {
    if (i == 1) {
      remove(this.frame2[2]);
      remove(this.frame2[1]);
      this.frame2[1] = new JSplitPane(0, this.frame2[0], this.done);
      add(this.frame2[1]);
    } 
  }
  
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == this.done) {
      if (Window_main.mode == 1) {
     for (int i = 0; i < 2; i++) 
    	 contain[i] = this.cin[i].getText(); 	        
        Window_main.mode = 2;
      } 
      else if (Window_main.mode == 4) {
    	  for (int i = 0; i < 3; i++) 
    		  contain[i] = this.cin[i].getText();
        Window_main.mode = 5;
      } 
      Window_main.jump();
    } else {
      for (int i = 0; i < 3; i++) {
        if (this.cin[i] == e.getSource())
          contain[i] = this.cin[i].getText(); 
      } 
    } 
  }
}
